package com.hmy.finance.manager.uua;


import com.alibaba.fastjson.JSON;
import com.hmy.ccp.common.result.FeignResult;
import com.hmy.ccp.error.exception.HMYRuntimeException;
import com.hmy.uaa.api.bo.request.QueryDepartmentRequest;
import com.hmy.uaa.api.bo.request.QueryUserInfoRequest;
import com.hmy.uaa.api.bo.response.QueryDepartmentResponse;
import com.hmy.uaa.api.bo.response.user.UserInfoResponse;
import com.hmy.uaa.api.client.user.UserFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Component
@Slf4j
public class UserFeignClientRpc {

    /**
     *
     */
    @Resource
    private UserFeignClient userFeignClient;

    public List<UserInfoResponse> getUserInfoList(QueryUserInfoRequest request) {
        log.info("UserFeignClientRpc#getUserInfoList param is:{}", request);
        FeignResult<List<UserInfoResponse>> result = userFeignClient.getUserInfoList(request);
        if (Objects.isNull(result)) {
            log.error("UserFeignClientRpc#getUserInfoList  is null");
            throw new HMYRuntimeException(506300006);
        }
        log.info("UserFeignClientRpc#getUserInfoList  result is:{}", JSON.toJSONString(result));
        if (result.isFailed()) {
            throw new HMYRuntimeException(result.getMsgCode(), result.getErrorText());
        }
        return result.getData();
    }


}
